package demo10.iterator.dinermerger;

import java.util.Calendar;
/**
 * 交流迭代器餐厅菜单
 * 迭代器模式---分装遍历依赖迭代器接口
 * */
public class AlternatingDinerMenuIterator implements Iterator{
	MenuItem[] list;
	int position;

	public AlternatingDinerMenuIterator(MenuItem[] list) {
		this.list = list;
		position = Calendar.DAY_OF_WEEK % 2;
	}
	@Override
	public MenuItem next() {
		MenuItem menuItem = list[position];
		position = position + 2;
		return menuItem;
	}
	@Override
	public boolean hasNext() {
		if (position >= list.length || list[position] == null) {
			return false;
		} else {
			return true;
		}
	}
	@Override
	public String toString() {
		return "交流迭代器餐厅菜单";
	}

}
